﻿@{
    ViewBag.Title = "编辑图片";
    Layout = "~/Areas/Shared/_spEdit.cshtml";
   
}
@using Kaiser.Extensions
@model Kaiser.Modules.Cubic.DomainModel.Product.Photo
<link href="@Url.Content("~/Scripts/Uploadify/3.1/uploadify.css")" rel="stylesheet"  type="text/css" />
<script src="@Url.Content("~/Scripts/Uploadify/3.1/swfobject.js")"   type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Uploadify/3.1/jquery.uploadify-3.1.min.js")"   type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Plugins/jquery-jtemplates.js")"   type="text/javascript"></script>
<script type="text/javascript"   src="@Url.Content("~/Scripts/ueditor/editor_config.js")"></script>
<script type="text/javascript"  src="@Url.Content("~/Scripts/ueditor/editor_all_min.js")"></script>
<script type="text/javascript">
  
    window.UEDITOR_CONFIG.initialFrameHeight = 150;
</script>

<form method="post" >
    <table>
        <tr>
            <td nowrap="nowrap">标题：
            </td>
            <td>
                @Html.Hidden("Id", Model.Id)
                @Html.HiddenFor(m => Model.ProductId, new { Value = Request["ProductId"] })
                @Html.TextBoxFor(x => Model.Name,new { @Style = "width:450px"})
            </td>
        </tr>
        <tr>
            <td>描述：
            </td>
            <td>  @Html.TextAreaFor(m => Model.Description,new{ @Class = "editor"})</td>
        </tr>
            <tr>
            <td>类型：
            </td>
            <td>  @Html.DropDownListFor(m => Model.Type,new []
                      {
                          new SelectListItem(){Text="顶部图片",Selected=Model.Type=="Top",Value = "Top"},
                             new SelectListItem(){Text="产品图片",Selected=string.IsNullOrWhiteSpace(Model.Type),Value = ""},
                               new SelectListItem(){Text="缩略图",Selected=Model.Type=="Thumbnail",Value = "Thumbnail"} 
                      })</td>
        </tr>

    </table>
        <div class="ftitle">图片</div>
    <div style="margin-top: 2px">
        @Html.HiddenFor(m => Model.Url, new { @Class = "attach" })
    </div>
    <div id="some_file_queue" class="some_file_queue" style="margin-left: 4px; float: left">
    </div>
</form>

<script type="text/javascript">
    $(".attach").each(function () {
        var o = $(this);
        var oid = o.attr("id");
        var attach = $('<div id="' + oid + '_attach"><div>');
        o.after(attach);
        attach.uploadify({
            'formData': { "ObjectID": $("#Id").val(), "ObjectModule": "ProductPhoto" },
            'swf': '@Url.Content("~/Scripts/Uploadify/3.1/uploadify.swf")',
            'uploader': '@Url.Action("UploadFiles", "ProductManage", new { area = "Hiner" })',
            'buttonImage': '@Url.Content("~/Themes/images/Snap1.jpg")',
            height: 88,
            'queueID': 'some_file_queue',
            'buttonCursor': 'arrow',
            "buttonText": "点我上传",
            onInit: function (instance) {
                var obj = $("#" + instance.settings.id);

                if (o.val() != '') {
                    obj.find(".uploadify-button").hide();
                    obj.find("img").remove();
                    obj.append('<img width=120 height=88  style="border: 1px solid #95b8e7" src="' + o.val() + '" />');

                }

            },
            onUploadSuccess: function (a, b) {
                var result = $.parseJSON(b);
                if (result.msg != "" && result.msg != undefined) {
                    alert(result.msg);
                } else {
                    var obj = $(this.wrapper[0]);
                    obj.find(".uploadify-button").hide();
                    obj.find("img").remove();
                    obj.append('<img width=120 height=88  style="border: 1px solid #95b8e7" src="' + result.Data.FilePath + '" />');
                    o.val(result.Data.FilePath);
                    // var o = $(this.wrapper[0], "img").attr('src', result.Data.FilePath);
                    //   $("#fileToUpload222-button").html("background-image", "url('" + result.Data.FilePath + "')").before("<img width=80 height=80 src='" + result.Data.FilePath + "' />");

                }
            }
        });
    });
</script>
